#include <iostream>
#include <vector>

#include "OnnxMlirRuntime.h"

// Declare the inference entry point.
extern "C" OMTensorList *run_main_graph(OMTensorList *);

static float img_data[] = {-0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.029637714847922325f, 0.7467845678329468f,
    1.7777715921401978f, 2.796030282974243f, 1.5104787349700928f,
    1.5104787349700928f, 0.36493754386901855f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.09764464199542999f, 2.5414655208587646f,
    2.783302068710327f, 2.796030282974243f, 2.783302068710327f,
    2.796030282974243f, 2.783302068710327f, 2.4141831398010254f,
    0.6067740321159363f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.4922199249267578f, 2.5414655208587646f,
    2.808758497238159f, 1.7650433778762817f, -0.4242129623889923f,
    -0.4242129623889923f, 2.0323362350463867f, 2.796030282974243f,
    2.808758497238159f, 2.2869009971618652f, -0.15692004561424255f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.09764464199542999f, 2.796030282974243f,
    2.783302068710327f, 1.2431857585906982f, -0.2969306409358978f,
    -0.4242129623889923f, -0.4242129623889923f, 0.4794916808605194f,
    2.783302068710327f, 2.796030282974243f, 2.783302068710327f,
    1.3831963539123535f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.2842023968696594f, 1.7777715921401978f,
    2.808758497238159f, 2.5414655208587646f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    0.09764464199542999f, 2.668747901916504f, 2.808758497238159f,
    2.796030282974243f, 2.808758497238159f, 1.7650433778762817f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 0.22492696344852448f,
    2.783302068710327f, 2.796030282974243f, 0.466763436794281f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 2.159618616104126f,
    1.4977505207061768f, 2.5287373065948486f, 2.796030282974243f,
    2.783302068710327f, 0.6195022463798523f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    1.5104787349700928f, 2.796030282974243f, 2.68147611618042f,
    0.08491640537977219f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    0.09764464199542999f, -0.4242129623889923f, 0.6195022463798523f,
    2.5541937351226807f, 2.796030282974243f, 2.5541937351226807f,
    -0.042365945875644684f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    0.09764464199542999f, 2.5414655208587646f, 2.783302068710327f,
    1.6377609968185425f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 1.0013492107391357f, 2.783302068710327f,
    2.796030282974243f, 1.7650433778762817f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.8740668296813965f, 2.808758497238159f,
    2.796030282974243f, 0.6195022463798523f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.15692004561424255f,
    2.4141831398010254f, 2.808758497238159f, 2.796030282974243f,
    0.36493754386901855f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 1.3831963539123535f,
    2.796030282974243f, 2.783302068710327f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 1.1286314725875854f, 2.796030282974243f,
    2.783302068710327f, 0.8740668296813965f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.029637714847922325f,
    2.5414655208587646f, 2.808758497238159f, 2.796030282974243f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    2.808758497238159f, 2.796030282974243f, 2.159618616104126f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    0.22492696344852448f, 2.783302068710327f, 2.796030282974243f,
    2.783302068710327f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 2.796030282974243f, 2.783302068710327f,
    2.159618616104126f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.22492696344852448f, 2.796030282974243f,
    2.808758497238159f, 2.796030282974243f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.15692004561424255f, 2.808758497238159f,
    2.796030282974243f, 1.3831963539123535f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 0.22492696344852448f,
    2.783302068710327f, 2.796030282974243f, 2.783302068710327f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 0.8740668296813965f,
    2.796030282974243f, 2.783302068710327f, 0.8740668296813965f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 1.905053973197937f, 2.808758497238159f,
    2.796030282974243f, 1.6504892110824585f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.029637714847922325f,
    2.5414655208587646f, 2.808758497238159f, 2.5414655208587646f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 0.8740668296813965f,
    2.796030282974243f, 2.783302068710327f, 2.668747901916504f,
    0.08491640537977219f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    1.2559140920639038f, 2.783302068710327f, 2.796030282974243f,
    0.466763436794281f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 1.7777715921401978f, 2.796030282974243f,
    2.821486711502075f, 2.796030282974243f, 0.6195022463798523f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    0.6195022463798523f, 2.808758497238159f, 2.796030282974243f,
    1.1413596868515015f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.2969306409358978f,
    1.7650433778762817f, 2.796030282974243f, 2.783302068710327f,
    2.668747901916504f, 1.6377609968185425f, 0.09764464199542999f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    1.6504892110824585f, 2.668747901916504f, 2.796030282974243f,
    2.274172782897949f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, 1.1413596868515015f,
    2.668747901916504f, 2.808758497238159f, 2.796030282974243f,
    2.5541937351226807f, 1.5104787349700928f, 1.5232069492340088f,
    2.5414655208587646f, 2.808758497238159f, 2.5414655208587646f,
    1.1413596868515015f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, 0.08491640537977219f, 1.4977505207061768f,
    2.5287373065948486f, 2.796030282974243f, 2.783302068710327f,
    2.796030282974243f, 2.783302068710327f, 1.4977505207061768f,
    0.21219873428344727f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f, -0.4242129623889923f,
    -0.4242129623889923f, -0.4242129623889923f};

int main() {
  // Create an input tensor list of 1 tensor.
  int inputNum = 1;
  OMTensor *inputTensors[inputNum];
  // The first input is of tensor<1x1x28x28xf32>.
  int64_t rank = 4;
  int64_t shape[] = {1, 1, 28, 28};
  OMTensor *tensor = omTensorCreate(img_data, shape, rank, ONNX_TYPE_FLOAT);
  // Create a tensor list.
  inputTensors[0] = tensor;
  OMTensorList *tensorListIn = omTensorListCreate(inputTensors, inputNum);

  // Compute outputs.
  OMTensorList *tensorListOut = run_main_graph(tensorListIn);

  // Free the input as it is no longer needed.
  omTensorListDestroy(tensorListIn);

  // Extract the output. The model defines one output of type tensor<1x10xf32>.
  OMTensor *y = omTensorListGetOmtByIndex(tensorListOut, 0);
  float *prediction = (float *)omTensorGetDataPtr(y);

  // Analyze the output.
  int digit = -1;
  float prob = 0.;
  for (int i = 0; i < 10; i++) {
    printf("prediction[%d] = %f\n", i, prediction[i]);
    if (prediction[i] > prob) {
      digit = i;
      prob = prediction[i];
    }
  }

  // Free the output as it is no longer needed.
  omTensorListDestroy(tensorListOut);

  printf("The digit is %d\n", digit);
  return 0;
}
